﻿using ZR.Model.System.Generate;
using ZR.Model.System.Model.Enums;
using SysEnum = System.Enum;

namespace ZR.Model.System.Dto
{
    public class GenTableDto
    {
        /// <summary>
        /// 生成表标识
        /// </summary>
        public int TableId { get; set; }

        /// <summary>
        /// 生成表名
        /// </summary>
        public string TableName { get; set; }

        /// <summary>
        /// 表描述
        /// </summary>
        public string TableComment { get; set; }

        /// <summary>
        /// 子表名
        /// </summary>
        public string SubTableName { get; set; }

        /// <summary>
        /// 子表主键名
        /// </summary>
        public string SubTableFkName { get; set; }

        /// <summary>
        /// 实体类名
        /// </summary>
        public string EntityClassName { get; set; }

        /// <summary>
        /// 模板分类
        /// </summary>
        public string TplCategory { get; set; }

        /// <summary>
        /// 基础命名空间
        /// </summary>
        public string BaseNameSpace { get; set; }

        /// <summary>
        /// 模块编码
        /// </summary>
        public string ModuleCode { get; set; }

        /// <summary>
        /// 模块名
        /// </summary>
        public string ModuleName { get; set; }

        /// <summary>
        /// 功能编码
        /// </summary>
        public string FunctionCode { get; set; }

        /// <summary>
        /// 功能名
        /// </summary>
        public string FunctionName { get; set; }

        /// <summary>
        /// 功能作者
        /// </summary>
        public string FunctionAuthor { get; set; }

        /// <summary>
        /// 生成类型
        /// </summary>
        public string GenType { get; set; }

        /// <summary>
        /// 生成路径
        /// </summary>
        public string GenPath { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 额外参数
        /// </summary>
        public CodeOptions Params { get; set; }

        /// <summary>
        /// 表列集合
        /// </summary>
        public List<GenTableColumnDto> Columns { get; set; }
    }

    public class GenTableColumnDto
    {
        /// <summary>
        /// 列标识
        /// </summary>
        public int ColumnId { get; set; }

        /// <summary>
        /// 表标识
        /// </summary>
        public int TableId { get; set; }

        /// <summary>
        /// 字段描述
        /// </summary>
        public string FieldDesc { get; set; }

        /// <summary>
        /// C#类型
        /// </summary>
        public string CsharpType { get; set; }

        /// <summary>
        /// C#字段名
        /// </summary>
        public string CsharpField { get; set; }

        /// <summary>
        /// 列位置串
        /// </summary>
        public string[] ColPositionStrs { get; set; }

        /// <summary>
        /// 列位置枚举
        /// </summary>
        public ColPositionEnum? ColPosition
        {
            get
            {
                ColPositionEnum? finalEnum = null;
                if (ColPositionStrs == null || ColPositionStrs.Length<=0)
                {
                    return finalEnum;
                }
               
                foreach(var item in ColPositionStrs)
                {
                    ColPositionEnum colPosition;
                    var isOk = SysEnum.TryParse(item, out colPosition);
                    if (isOk && SysEnum.IsDefined<ColPositionEnum>(colPosition))
                    {
                        if (finalEnum == null)
                        {
                            finalEnum = colPosition;
                        }
                        else
                        {
                            finalEnum = finalEnum ^ colPosition;
                        }
                    }

                }
                return finalEnum;
            }
        }

        /// <summary>
        /// 赋值位置串
        /// </summary>
        public string[] SetPositionStrs { get; set; }

        /// <summary>
        /// 赋值位置枚举
        /// </summary>
        public SetPositionEnum? SetPosition
        {
            get
            {
                SetPositionEnum? finalEnum = null;
                if (SetPositionStrs == null || SetPositionStrs.Length <= 0)
                {
                    return finalEnum;
                }

                foreach (var item in SetPositionStrs)
                {
                    SetPositionEnum setPosition;
                    var isOk = SysEnum.TryParse(item, out setPosition);
                    if (isOk && SysEnum.IsDefined<SetPositionEnum>(setPosition))
                    {
                        if (finalEnum == null)
                        {
                            finalEnum = setPosition;
                        }
                        else
                        {
                            finalEnum = finalEnum ^ setPosition;
                        }
                    }

                }
                return finalEnum;
            }
        }

        public bool IsInsert { get; set; }
        public bool IsEdit { get; set; }
        public bool IsList { get; set; }
        public bool IsQuery { get; set; }
        public bool IsSort { get; set; }
        public bool IsRequired { get; set; }
        public bool IsExport { get; set; }

        /// <summary>
        /// 显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）
        /// </summary>
        public string HtmlType { get; set; }

        /// <summary>
        /// 查询类型（等于、不等于、大于、小于、范围）
        /// </summary>
        public string QueryType { get; set; } = "EQ";

        /// <summary>
        /// 排序编号
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 字典类型
        /// </summary>
        public string DictType { get; set; }

        /// <summary>
        /// 自定义组件
        /// </summary>
        public string CustomCtl { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 自动填充类型
        /// </summary>
        public int? AutoFillType { get; set; }
    }
}
